import operator
from itertools import count,cycle,repeat
#无限迭代器
#count:start+step
for i in count(start=0,step=1):
    print(i)
    if i >=100:
        break

#cycle(iterable):不断遍历iterable
counter = 0
for j in cycle("hello"):
    print(j)
    counter += 1
    if counter >= 10:  # Stop after 10 iterations
        break

#repeat(object,times]):objict循环times次
for n in repeat('a',10):
    print(n)

from itertools import accumulate,chain
#有限迭代器
a=[3,2,5,8,4]
b=accumulate(a)
c=accumulate(a,max)
d=accumulate(a,operator.mul)
print(list(b))#[3, 5, 10, 18, 22] 3+2,3+2+5,3+2+5+8,...
print(list(c))#[3, 3, 5, 8, 8] 3 3>2 5>3 8>5
print(list(d))#[3, 6, 30, 240, 960] 3*2 3*2*5...

print(list(chain('abc','123')))#组合两个部分

from itertools import product,permutations,combinations
#排列组合迭代器
print(list(product([1,2,3],[4,5,6])))
"""
[(1, 4), (1, 5), (1, 6), (2, 4), (2, 5), (2, 6), (3, 4), (3, 5), (3, 6)]
[1,2,3]  [4,5,6]
14 15 16 24 25...
product([1,2,3],[1,2,3])==product([1,2,3],repeat=2)
"""
print(list(permutations([1,2,3])))#[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]所有排列方式
print(list(permutations([1,2,3,4],2)))#任意选取两个数(1,2)跟(2,1)不同

print(list(combinations([1,2,3,4],2)))#组合，(1,2)跟(2,1)相同